package com.budwk.app.sqfw.controllers.admin.guiyang.guanshanhu;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfw.component.CommunityStreetComponent;
import com.budwk.app.sqfw.enums.BusinessTypeA17Enum;
import com.budwk.app.sqfw.enums.FireElectricityUsageEnum;
import com.budwk.app.sqfw.enums.StreetEnum;
import com.budwk.app.sqfw.models.Sqfw_formSummary;
import com.budwk.app.sqfw.services.SecurityInvestigationService;
import com.budwk.app.sqfw.services.SqfwFormSummaryService;
import com.budwk.app.sqfw.vo.Sqfw_formSummaryForAdminVO;
import com.budwk.starter.common.openapi.annotation.*;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @author ZY.Wang
 * @since 2023/10/23
 */
@IocBean
@At("/platform/sqfw/guanshanhu/yuntan")
@ApiDefinition(tag = "贵阳观山湖云潭街道（宇虹社区）接口")
@Slf4j
public class YunTanStreeController {

    @Inject
    private CommunityStreetComponent communityStreetComponent;

    @Inject(value = "yunTanStreetService")
    private SecurityInvestigationService investigationService;

    @Inject
    private SqfwFormSummaryService sqfwFormSummaryService;

    @At()
    @Ok("json")
    @POST
    @ApiOperation(name = "后台管理系统任务列表查询")
    @ApiFormParams(implementation = Sqfw_formSummaryForAdminVO.class)
    @ApiResponses(implementation = Sqfw_formSummary.class)
    @SaCheckLogin
    public Result<?> listSummaryByPage(@Param("..") Sqfw_formSummaryForAdminVO forAdminVo) {
        log.info("yunTanStreeController listSummaryByJY param: {}", JSONObject.toJSONString(forAdminVo));
        return investigationService.listSummaryByPage(forAdminVo);
    }

    @At()
    @Ok("json")
    @GET
    @ApiOperation(name = "经营类型（搜索a17；需要穷举：全部 / 个体工商户 / 企业）")
    @SaCheckLogin
    public Result<?> listA17Data() {
        return Result.data(BusinessTypeA17Enum.listNames());
    }

    @At()
    @Ok("json")
    @GET
    @ApiOperation(name = "用火用电情况：需要穷举： 全部 / 使用醇基 / 使用液化气 / 用电；搜索a6")
    @SaCheckLogin
    public Result<?> listFireUsage() {
        return Result.data(FireElectricityUsageEnum.listNames());
    }

    @At()
    @Ok("json")
    @DELETE
    @ApiOperation(name = "根据id删除数据")
    @ApiImplicitParams(@ApiImplicitParam(name = "sqfwFormSummaryId", description = "当前操作数据id", required = true, check = true))
    @ApiImplicitParam(name = "sqfwFormSummaryId", description = "当前操作数据id", required = true, check = true)
    @SLog(tag = "云潭街道：根据id删除数据", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> deleteById(@Param("sqfwFormSummaryId") String sqfwFormSummaryId) {
        log.info("yunTanStreeController deleteById param: {}", sqfwFormSummaryId);
        communityStreetComponent.deleteFormSummary(sqfwFormSummaryId);
        return Result.success();
    }

    @At()
    @Ok("json")
    @POST
    @ApiOperation(name = "查询导出：按照条件导出PDF,根据服务记录id数组生成pdf合集zip")
    @ApiFormParams(implementation = Sqfw_formSummaryForAdminVO.class)
    @SaCheckLogin
    public Result<?> generateServiceRecordPdfCollZipForBM(@Param("..") Sqfw_formSummaryForAdminVO bean) {
        return Result.data(investigationService.generateServiceRecordPdfCollZipForBM(bean));
    }

    @At()
    @Ok("json")
    @POST
    @ApiOperation(name = "查询导出：按照条件导出excel, 根据服务记录id和汇总Id数组生成Excel合集")
    @ApiFormParams(implementation = Sqfw_formSummaryForAdminVO.class)
    @SaCheckLogin
    public Result<?> generateServiceRecordExcelCollZipForBM(@Param("..") Sqfw_formSummaryForAdminVO bean) {
        return Result.data(investigationService.generateServiceRecordExcelCollZipForBM(bean));
    }

    /**
     * 根据 index 下载模板（pdf）
     *
     * @return
     * @Date 2023-11-23
     */
    @At("/downloadTemplateForIndex")
    @Ok("json")
    @POST
    @ApiOperation(name = "模板下载")
    @SLog(tag = "模板下载", value = "")
    @SaCheckLogin
    public Result<?> downloadTemplateForIndex( @Param("fileIndex") Integer fileIndex, @NotNull @Param("isWord") String isWord) {
        return Result.data(sqfwFormSummaryService.downloadTemplateForIndex(fileIndex,  isWord, StreetEnum.YUN_TAN_STREET.getName()));
    }
}
